<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 2018/8/27
 * Time: 15:19
 */

namespace Biz\module\Classes\mgt;

use Biz\module\Classes\OrderPackage as clsOrderPackage;
use Biz\service\trade\Logistics as sLogistics;
use Biz\model\trade\Order as mOrder;
use Biz\model\trade\OrderPackage as mOrderPackage;
use Biz\model\trade\OrderGoods as mOrderGoods;
use Biz\module\Classes\OrderRefund as clsOrderRefund;
use Biz\model\trade\OrderRefund as mOrderRefund;

class OrderInfo extends \Biz\module\Classes\OrderInfo
{


    //获取可以发货的sku列表
    public static function getCanShipSkuIds($shopId,$orderNo){

        $orderInfo = mOrder::getOrderInfo($orderNo);

        if(empty($orderInfo)){
            throw new \Exception('订单不存在');
        }

        if($orderInfo['shop_id'] != $shopId){
            throw new \Exception('订单不存在');
        }

        if($orderInfo['status'] == mOrder::STATUS_SEND_OUT){
            throw new \Exception('订单状态不正确');
        }

        $skuIdList = mOrderGoods::getSkuIds($orderNo);

        $shipedSkuIds = mOrderPackage::getAllPackageSkuIds($orderNo);

        if(!empty($shipedSkuIds)){
            $skuIdList = array_diff($skuIdList,$shipedSkuIds);
        }

        //排除掉退款成功的skuid
        $succRefund = mOrderRefund::getRefundSuccessList($orderNo);
        $succRefundSkuIds = array_unique(array_keys($succRefund));

        if(!empty($succRefundSkuIds)){
            $skuIdList = array_diff($skuIdList,$succRefundSkuIds);
        }


        $skuInfoList = mOrderGoods::getOrderGoodsList($orderNo,$skuIdList,'sku_id',['sku_id','title','sku_desc','cover_img','goods_id','buy_num']);

        return array_values($skuInfoList);
    }

}